//
//  XZPopCommentVC.m
//  Teecloud
//
//  Created by PC on 2018/11/13.
//  Copyright © 2018年 小志. All rights reserved.
//

#import "XZPopCommentVC.h"
#import "GMTextView.h"
#import "GMAudioView.h"
#import "GMPhotoCell.h"
#import "TZImagePickerController.h"
#import "GMChoseFileVC.h"
#import <KSPhotoBrowser/KSPhotoBrowser.h>
#import "GMFileModel.h"
#import "RecordHUD.h"
#import "D3RecordButton.h"
#import "XZGradeView.h"
@interface XZPopCommentVC ()<UICollectionViewDataSource,UICollectionViewDelegate,XMGWaterflowLayoutDelegate,TZImagePickerControllerDelegate,D3RecordDelegate>
@property (weak, nonatomic) IBOutlet D3RecordButton *btn;
@property (weak, nonatomic) IBOutlet UIView *bagView;
@property (weak, nonatomic) IBOutlet UIScrollView *scollview;
@property (weak, nonatomic) IBOutlet UIButton *changeBtn;


@property (weak, nonatomic) IBOutlet UILabel *titleLeft;
@property (weak, nonatomic) IBOutlet UILabel *titleRight;
@property (weak, nonatomic) IBOutlet UIImageView *titleArrow;
/*评分的view*/
@property (nonatomic, strong) XZGradeView *gradeView;

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) GMTextView *textView;
@property (nonatomic, strong) GMAudioView *audioView;
@property (nonatomic, assign) BOOL isAudio;
/**本地图片数组*/
@property (nonatomic, strong) NSMutableArray *imgArr;
@property(nonatomic,assign)NSInteger maxCount;//最多个数
/**上传到服务器的图片模型数组*/
@property (nonatomic, strong) NSMutableArray *netImgArr;
/**本地语音*/
@property (nonatomic, strong) NSMutableArray *audioArr;
/**上传到服务器的语音数组*/
@property (nonatomic, strong) NSMutableArray *netaudioArr;
//code=7/8时的selectValue 同意=2 不同意=3
@property (nonatomic, copy) NSString *code;
//点评 等级 优=1,良=2,中=3,差=4；
@property (nonatomic, copy) NSString *remarkCode;
//分数 1- 100分
@property (nonatomic, copy) NSString *gradeCode;
@end

@implementation XZPopCommentVC
-(void)dealloc{
    XZLog(@"%s",__FUNCTION__);
    /**页面销毁的时候移除通知*/
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.textView.isNotStar = NO;
    self.maxCount = 5;/**设置最大图片数量*/
    self.scollview.scrollEnabled = false;
    self.scollview.contentSize = CGSizeMake(DEVICE_WIDTH*2, 0);
    [self.scollview addSubview:self.textView];
    [self.scollview addSubview:self.audioView];
    [self.collectionView registerNib:[UINib nibWithNibName:@"GMPhotoCell" bundle:nil] forCellWithReuseIdentifier:@"GMPhotoCell"];
    [_btn initRecord:self maxtime:120 title:@"上滑取消录音"];
    self.btn.hidden = YES;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updataBtnSatate) name:@"updataBtn" object:nil];
    
    //给选项标签添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(chooseTag)];
    self.titleRight.userInteractionEnabled = YES;
    [self.titleRight addGestureRecognizer:tap];
    
    [self hiddenUI:self.model];
}
//根据相应的值来显示隐藏控件
- (void)hiddenUI:(XZMsgList *)model{
    self.titleArrow.hidden = false;
    self.titleRight.hidden = false;
    NSInteger code = [model.Action.Code integerValue];
    if (code <= 5) {
        //隐藏右边的标签跟箭头
        self.titleArrow.hidden = true;
        self.titleRight.hidden = true;
        //根据操作代码的不同来展示不同的标签名称
        if ([model.Action.Code isEqualToString:@"1"]) {
            self.titleLeft.text = @"消息回复";
        }else if ([model.Action.Code isEqualToString:@"2"]){
            self.titleLeft.text = @"提问回答";
        }else if ([model.Action.Code isEqualToString:@"3"]){
            self.titleLeft.text = @"回答追问";
        }else if ([model.Action.Code isEqualToString:@"4"]){
            self.titleLeft.text = @"评论解释";
        }else if ([model.Action.Code isEqualToString:@"5"]){
            self.titleLeft.text = [NSString stringWithFormat:@"%@反馈",model.Action.GroupInfo.Title];
        }
    }else if (code == 6){
        if ([model.Action.GroupInfo.Option isEqualToString:@"1"]) {
            self.titleLeft.text = [NSString stringWithFormat:@"%@回复",model.Action.GroupInfo.Title];
            self.titleArrow.hidden = true;
            self.titleRight.hidden = true;
        }else{
            self.titleLeft.text = [NSString stringWithFormat:@"%@点评",model.Action.GroupInfo.Title];
            self.titleArrow.hidden = false;
            self.titleRight.hidden = false;
            //可选项有：优=1,良=2,中=3,差=4；选择提示信息：请选择点评评级
            if ([model.Action.GroupInfo.CheckType isEqualToString:@"1"]) {
                self.titleRight.text = @"请选择点评评级";
            }else if ([model.Action.GroupInfo.CheckType isEqualToString:@"2"]){
                //可选项有：1分=1,2分=2,...,99分=99,100分=100；选择提示信息：请选择点评评分
                self.titleRight.text = @"请选择点评评分";
            }
        }
    }else if (code == 7){
        //操作代码=7时为“请假审批”，=8时为“加入申请审核”
        //提示信息：操作代码=7时为“请选择审批结果”，=8时为“请选择审核结果”；可选项都为：同意=2，不同意=3；
        //打开右边的标签跟箭头
        self.titleArrow.hidden = false;
        self.titleRight.hidden = false;
        self.titleLeft.text = @"请假审批";
        self.titleRight.text = @"请选择审批结果";
    }else if (code == 8){
        self.titleArrow.hidden = false;
        self.titleRight.hidden = false;
        self.titleLeft.text = @"加入申请审核";
        self.titleRight.text = @"请选择审核结果";
    }
}
//选择
- (void)chooseTag{
    NSInteger code = [self.model.Action.Code integerValue];
    //审核 审批
    if (code == 7 || code == 8) {
        //显示弹出框列表选择
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.titleRight.text
                                                                       message:nil
                                                                preferredStyle:UIAlertControllerStyleActionSheet];
        
        UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel
                                                             handler:^(UIAlertAction * action) {
                                                                 XZLog(@"action = %@", action);
                                                             }];
        UIAlertAction* manAction = [UIAlertAction actionWithTitle:@"同意" style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {
                                                              //响应事件
                                                              self.titleRight.text = action.title;
                                                              self.code = @"2";
                                                          }];
        UIAlertAction* womanAction = [UIAlertAction actionWithTitle:@"不同意" style:UIAlertActionStyleDefault
                                                            handler:^(UIAlertAction * action) {
                                                                //响应事件
                                                                self.titleRight.text = action.title;
                                                                self.code = @"3";
                                                            }];
        [alert addAction:cancelAction];
        [alert addAction:manAction];
        [alert addAction:womanAction];
        [self presentViewController:alert animated:YES completion:nil];
    }
    //点评
    if (code == 6) {
        //CheckType=1，可选项有：优=1,良=2,中=3,差=4
        if ([self.model.Action.GroupInfo.CheckType isEqualToString:@"1"]) {
            [self remarkon];
        }else{
            //评分
            [self.gradeView show];
        }
    }
}
//点评优良中差
- (void)remarkon{
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.titleRight.text
                                                                   message:nil
                                                            preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel
                                                         handler:^(UIAlertAction * action) {
                                                             XZLog(@"action = %@", action);
                                                         }];
    UIAlertAction* excellentAction = [UIAlertAction actionWithTitle:@"优" style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction * action) {
                                                          //响应事件
                                                          self.titleRight.text = action.title;
                                                          self.remarkCode = @"1";
                                                      }];
    UIAlertAction* goodAction = [UIAlertAction actionWithTitle:@"良" style:UIAlertActionStyleDefault
                                                        handler:^(UIAlertAction * action) {
                                                            //响应事件
                                                            self.titleRight.text = action.title;
                                                               self.remarkCode = @"2";
                                                        }];
    UIAlertAction* middleAction = [UIAlertAction actionWithTitle:@"中" style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction * action) {
                                                           //响应事件
                                                           self.titleRight.text = action.title;
                                                           self.remarkCode = @"3";
                                                       }];
    UIAlertAction* badAction = [UIAlertAction actionWithTitle:@"差" style:UIAlertActionStyleDefault
                                                         handler:^(UIAlertAction * action) {
                                                             //响应事件
                                                             self.titleRight.text = action.title;
                                                                  self.remarkCode = @"4";
                                                         }];
    
    [alert addAction:cancelAction];
    [alert addAction:excellentAction];
    [alert addAction:goodAction];
    [alert addAction:middleAction];
    [alert addAction:badAction];
    [self presentViewController:alert animated:YES completion:nil];
}

-(void)endRecord:(NSData *)voiceData{
    [self.audioArr addObject:voiceData];
    self.audioView.dataArr = self.audioArr;
    if (self.audioArr.count >2) {
        self.btn.backgroundColor = kDarkGrayColor;
        [self.btn setTitle:@"限制录制三段语音" forState:UIControlStateNormal];
        self.btn.userInteractionEnabled = NO;
    }else{
        self.btn.backgroundColor = [UIColor colorWithHexString:@"007AFF"];
        [self.btn setTitle:@"长按录音" forState:UIControlStateNormal];
        self.btn.userInteractionEnabled = YES;
    }
}
-(void)updataBtnSatate{
    self.btn.backgroundColor = [UIColor colorWithHexString:@"007AFF"];
    [self.btn setTitle:@"长按录音" forState:UIControlStateNormal];
    self.btn.userInteractionEnabled = YES;
}
- (UICollectionView *)collectionView{
    if (!_collectionView) {
        //1.初始化layout
        // 创建布局
        XMGWaterflowLayout *layout = [[XMGWaterflowLayout alloc] init];
        layout.delegate = self;
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, DEVICE_WIDTH-30, 80) collectionViewLayout:layout];
        _collectionView.backgroundColor = kWhiteColor;
        _collectionView.dataSource = self;
        _collectionView.scrollEnabled = NO;
        _collectionView.delegate = self;
        [self.bagView addSubview:_collectionView];
        
    }
    return _collectionView;
}
-(NSMutableArray *)netaudioArr{
    if (!_netaudioArr) {
        _netaudioArr = [[NSMutableArray alloc] init];
    }
    return _netaudioArr;
}
-(NSMutableArray *)audioArr{
    if (!_audioArr) {
        _audioArr = [[NSMutableArray alloc] init];
    }
    return _audioArr;
}
-(NSMutableArray *)netImgArr{
    if (!_netImgArr) {
        _netImgArr = [[NSMutableArray alloc] init];
    }
    return _netImgArr;
}
-(NSMutableArray *)imgArr{
    if (!_imgArr) {
        _imgArr = [[NSMutableArray alloc] init];
    }
    return _imgArr;
}
-(GMTextView *)textView{
    if (!_textView) {
        _textView = [GMTextView viewFromXib];
        _textView.isNotStar = NO;
        _textView.frame = CGRectMake(0, 0, DEVICE_WIDTH, 130);
    }
    return _textView;
}
-(GMAudioView *)audioView{
    if (!_audioView) {
        _audioView = [GMAudioView viewFromXib];
        _audioView.frame = CGRectMake(DEVICE_WIDTH, 0, DEVICE_WIDTH, 130);
    }
    return _audioView;
}
- (XZGradeView *)gradeView{
    if (!_gradeView) {
        kWeakObject(self)
        _gradeView =[XZGradeView viewFromXib];
        _gradeView.frame = CGRectMake(0, 0, DEVICE_WIDTH, DEVICE_HEIGHT);
        _gradeView.backgroundColor = kClearColor;
        _gradeView.gradeViewBlock = ^(NSString * _Nonnull grade) {
            //评分
            weakself.titleRight.text = grade;
            weakself.gradeCode = [grade substringToIndex:[grade length] - 1];
        };
    }
    return _gradeView;
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.imgArr.count+1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    GMPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GMPhotoCell" forIndexPath:indexPath];
    if (indexPath.row == self.imgArr.count || self.imgArr.count == 0) {
        cell.photoImg.image = [UIImage imageNamed:@"photo_add"];
        cell.delectBtn.hidden=YES;
    }else{
        NSDictionary *dict = self.imgArr[indexPath.row];
        NSString *name =[dict objectForKey:@"name"];
        if (kIsEmptyString(name)) {
            cell.photoImg.image = [dict objectForKey:@"image"];
        }else{
            cell.photoImg.image =[UIImage imageNamed:[dict objectForKey:@"image"]];
        }
        cell.delectBtn.hidden=NO;
        cell.delectBtn.tag = indexPath.row +1000;
        [cell.delectBtn addTarget:self action:@selector(delectImageWithBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return cell;
}
#pragma mark - <XMGWaterflowLayoutDelegate>
- (CGFloat)waterflowLayout:(XMGWaterflowLayout *)waterflowLayout heightForItemAtIndex:(NSUInteger)index itemWidth:(CGFloat)itemWidth{
    //计算item的高度
    return itemWidth;
}

- (CGFloat)rowMarginInWaterflowLayout:(XMGWaterflowLayout *)waterflowLayout{
    return 10;
}
/**返回每行的个数*/
- (CGFloat)columnCountInWaterflowLayout:(XMGWaterflowLayout *)waterflowLayout{
    return 5;
}

- (UIEdgeInsets)edgeInsetsInWaterflowLayout:(XMGWaterflowLayout *)waterflowLayout{
    return UIEdgeInsetsMake(10, 10, 10, 10);
}

//点击item方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    kWeakObject(self)
    if (indexPath.row == self.imgArr.count) {
        
        //显示弹出框列表选择
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil
                                                                       message:nil
                                                                preferredStyle:UIAlertControllerStyleActionSheet];
        
        UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel
                                                             handler:^(UIAlertAction * action) {
                                                                 //响应事件
                                                                 NSLog(@"action = %@", action);
                                                             }];
        UIAlertAction* manAction = [UIAlertAction actionWithTitle:@"选择文件" style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {
                                                              GMChoseFileVC *chose = [[GMChoseFileVC alloc] init];
                                                              chose.GMChoseFileVCBlock = ^(NSDictionary *dict) {
                                                                  [weakself.imgArr addObject:dict];
                                                                  [weakself.collectionView reloadData];
                                                              };
                                                              [self presentViewController:chose animated:YES completion:nil];
                                                          }];
        UIAlertAction* womanAction = [UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDefault
                                                            handler:^(UIAlertAction * action) {
                                                                //响应事件
                                                                TZImagePickerController *pickerController = [[TZImagePickerController alloc]initWithMaxImagesCount:self.maxCount - self.imgArr.count delegate:self];
                                                                pickerController.sortAscendingByModificationDate = NO;
                                                                pickerController.showPhotoCannotSelectLayer = YES;
                                                                kWeakObject(self)
                                                                [pickerController setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photo, NSArray *assets, BOOL isSelectOriginalPhoto){
                                                                    
                                                                    if (photo.count) {
                                                                        [weakself addNewImages:photo];
                                                                    }
                                                                }];
                                                                [self presentViewController:pickerController animated:YES completion:nil];
                                                            }];
        [alert addAction:cancelAction];
        [alert addAction:manAction];
        [alert addAction:womanAction];
        [self presentViewController:alert animated:YES completion:nil];
        
    }
    
}
//添加多张图片--
-(void)addNewImages:(NSArray *)newImages{
    
    //默认多张图片选择顺序是按照用户选择顺序，所以这里进行反序，因为后面把刚添加的index 置为0；
    NSArray* images = [[newImages reverseObjectEnumerator] allObjects];
    [images enumerateObjectsUsingBlock:^(UIImage * obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSDictionary *imgDict = @{@"image":obj};
        [self.imgArr insertObject:imgDict atIndex:0];
        
    }];
    [self.collectionView reloadData];
    //先从服务器获取OSS需要的数据
    
}
- (void)delectImageWithBtn:(UIButton *)sender{
    NSInteger index =sender.tag -1000;
    [self.imgArr removeObjectAtIndex:index];
    [self.collectionView reloadData];
}
/*语音-文本切换*/
- (IBAction)changeViewButtonAction:(UIButton *)sender {
    if (self.isAudio) {
        self.btn.hidden = YES;
        self.scollview.contentOffset = CGPointMake(0, 0);
        [self.changeBtn setImage:[UIImage imageNamed:@"microphone-gray"] forState:UIControlStateNormal];
    }else{
        self.btn.hidden = NO;
        self.scollview.contentOffset = CGPointMake(DEVICE_WIDTH, 0);
        [self.changeBtn setImage:[UIImage imageNamed:@"keyboard"] forState:UIControlStateNormal];
    }
    _isAudio = !_isAudio;
}
/*取消*/
- (IBAction)cancleButtonAction:(id)sender {
    UIViewController * parent = [self.view containingViewController];
    if ([parent respondsToSelector:@selector(dismissSemiModalView)]) {
        [parent dismissSemiModalView];
    }
}

/*提交*/
- (IBAction)submitButtonAction:(UIButton *)sender {
    //Action.Code=7/8时 要勾选同意或者不同意
    NSInteger code = [self.model.Action.Code integerValue];
    if (code == 7 || code == 8) {//须勾选同意或者不同意
        if (![self.titleRight.text isEqualToString:@"不同意"] && ![self.titleRight.text isEqualToString:@"同意"]) {
            [MBProgressHUD showErrorOrSuc:self.titleRight.text toView:self.view];
            return;
        }
    }
    
    //点评
    if (code == 6) {
        //当等于2时才有等级 点评的选项卡
        if ([self.model.Action.GroupInfo.Option isEqualToString:@"2"]) {
            //点评等级
            if ([self.model.Action.GroupInfo.CheckType isEqualToString:@"1"]) {
                if (![self.titleRight.text isEqualToString:@"优"] &&
                    ![self.titleRight.text isEqualToString:@"良"]&&
                    ![self.titleRight.text isEqualToString:@"中"]&&
                    ![self.titleRight.text isEqualToString:@"差"]) {
                    [MBProgressHUD showErrorOrSuc:self.titleRight.text toView:self.view];
                    return;
                }
            }else{
                if (kIsEmptyString(self.gradeCode)) {
                    [MBProgressHUD showErrorOrSuc:@"请选择点评评分" toView:self.view];
                    return;
                }
            }
        }
    }
    
    
    //语音文本必须输入一样
    if (!(self.audioArr.count>0) && !(self.textView.textView.text.length > 0)) {
        [MBProgressHUD showErrorOrSuc:@"请提供文本消息或语音消息" toView:self.view];
        return;
    }
    dispatch_group_t uploadGroup = dispatch_group_create();
    for (NSInteger i =0; i<self.audioArr.count; i++) {
        dispatch_group_enter(uploadGroup);
        NSDictionary *dict= @{@"from":FROM_IOS,
                              @"busiOrgId":[XGMArchiverTools cacheForKey:BUSIORGID],
                              @"loginFinger":[XGMArchiverTools cacheForKey:USER_identifierNumber],
                              @"userId":[XGMArchiverTools cacheForKey:USER_UserId],
                              @"fileType":@"res-remark"
                              };
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyyMMddHHmmss"];
        NSString *dateString = [formatter stringFromDate:[NSDate date]];
        NSString *fileName = [NSString  stringWithFormat:@"%@.mp3", dateString];
        [HJNetwork uploadImageURL:[NSString stringWithFormat:@"/ajax-api.ashx?$c=TeeyunApp&$m=UploadFile&$v=%@",VERSION] parameters:dict imageData:self.audioArr[i] name:@"audio_file" fileName:fileName mimeType:@"audio/mpeg" progress:^(NSProgress *progress) {
            
        } callback:^(id responseObject, NSError *error) {
            if (!error) {
                if ([[responseObject objectForKey:RESULT_NAME_Success] boolValue]){
                    GMFileModel *model = [GMFileModel mj_objectWithKeyValues:[responseObject objectForKey:RESULT_NAME_Data]];
                    [self.netaudioArr addObject:model];
                    dispatch_group_leave(uploadGroup);
                }else{
                    /**显示错误信息*/
                    [MBProgressHUD showErrorOrSuc:[responseObject objectForKey:RESULT_NAME_Message] toView:self.view];
                }
            }
        }];
    }
    for (NSInteger i =0; i<self.imgArr.count; i++) {
        dispatch_group_enter(uploadGroup);
        NSDictionary *dict= @{@"from":FROM_IOS,
                              @"busiOrgId":[XGMArchiverTools cacheForKey:BUSIORGID],
                              @"loginFinger":[XGMArchiverTools cacheForKey:USER_identifierNumber],
                              @"userId":[XGMArchiverTools cacheForKey:USER_UserId],
                              @"fileType":@"res-remark"
                              };
        NSDictionary *temDict = self.imgArr[i];
        NSString *name =[temDict objectForKey:@"name"];
        UIImage *tempImg;
        if (kIsEmptyString(name)) {
            //上传图片
            tempImg = [temDict objectForKey:@"image"];
            NSData *imageData = UIImageJPEGRepresentation(tempImg, 0.5);
            NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
            [formatter setDateFormat:@"yyyyMMddHHmmss"];
            NSString *dateString = [formatter stringFromDate:[NSDate date]];
            NSString *fileName = [NSString  stringWithFormat:@"%@.jpg", dateString];
            [HJNetwork uploadImageURL:[NSString stringWithFormat:@"/ajax-api.ashx?$c=TeeyunApp&$m=UploadFile&$v=%@",VERSION] parameters:dict imageData:imageData name:@"file" fileName:fileName mimeType:@"image/jpeg" progress:^(NSProgress *progress) {
                
            } callback:^(id responseObject, NSError *error) {
                if (!error) {
                    if ([[responseObject objectForKey:RESULT_NAME_Success] boolValue]){
                        GMFileModel *model = [GMFileModel mj_objectWithKeyValues:[responseObject objectForKey:RESULT_NAME_Data]];
                        [self.netImgArr addObject:model];
                        dispatch_group_leave(uploadGroup);
                    }else{
                        /**显示错误信息*/
                        [MBProgressHUD showErrorOrSuc:[responseObject objectForKey:RESULT_NAME_Message] toView:self.view];
                    }
                }
            }];
        }else{
            //上传文件
            NSString *filePath = [temDict objectForKey:@"path"];
            NSData *fileData = [NSData dataWithContentsOfFile:filePath];
            NSString *fileName = [temDict objectForKey:@"name"];
            NSString *mimeType = @"";
            if ([fileName containsString:@"zip"]) {
                mimeType =@"application/zip";
            }else if ([fileName containsString:@"pdf"]) {
                mimeType =@"application/pdf";
            }else if ([fileName containsString:@"ppt"]) {
                mimeType =@"application/vnd.ms-powerpoint";
            }else if ([fileName containsString:@"docx"]) {
                mimeType =@"application/msword";
            }else if ([fileName containsString:@"excel"]) {
                mimeType =@"application/vnd.ms-excel";
            }else if ([fileName containsString:@"rar"]) {
                mimeType =@"application/x-rar-compressed";
            }else{
                mimeType =@"text/plain";
            }
            NSLog(@"%@",dict);
            [HJNetwork uploadImageURL:[NSString stringWithFormat:@"/ajax-api.ashx?$c=TeeyunApp&$m=UploadFile&$v=%@",VERSION] parameters:dict imageData:fileData name:@"file" fileName:fileName mimeType:mimeType progress:^(NSProgress *progress) {
                
            } callback:^(id responseObject, NSError *error) {
                if (!error) {
                    if ([[responseObject objectForKey:RESULT_NAME_Success] boolValue]){
                        GMFileModel *model = [GMFileModel mj_objectWithKeyValues:[responseObject objectForKey:RESULT_NAME_Data]];
                        [self.netImgArr addObject:model];
                        dispatch_group_leave(uploadGroup);
                    }else{
                        /**显示错误信息*/
                        [MBProgressHUD showErrorOrSuc:[responseObject objectForKey:RESULT_NAME_Message] toView:self.view];
                    }
                }
            }];
        }
    }
    dispatch_group_notify(uploadGroup, dispatch_get_main_queue(), ^{
        [self sumbitAllData];
    });
}

-(void)sumbitAllData{
    NSString *imgFile1Id =@"";
    NSString *imgFile2Id =@"";
    NSString *imgFile3Id =@"";
    NSString *imgFile4Id =@"";
    NSString *imgFile5Id =@"";
    for (NSInteger i=0; i<self.netImgArr.count; i++) {
        GMFileModel *model =self.netImgArr[i];
        switch (i) {
            case 0:{
                imgFile1Id =model.Id;
            }
                break;
            case 1:{
                imgFile2Id =model.Id;
            }
                break;
            case 2:{
                imgFile3Id =model.Id;
            }
                break;
            case 3:{
                imgFile4Id =model.Id;
            }
                break;
            case 4:{
                imgFile5Id =model.Id;
            }
                break;
                
            default:
                break;
        }
    }
    NSString *voice1Id =@"";
    NSString *voice2Id=@"";
    NSString *voice3Id =@"";
    for (NSInteger i=0; i<self.netaudioArr.count; i++) {
        GMFileModel *model =self.netaudioArr[i];
        switch (i) {
            case 0:{
                voice1Id =model.Id;
            }
                break;
            case 1:{
                voice2Id =model.Id;
            }
                break;
            case 2:{
                voice3Id =model.Id;
            }
                break;
            default:
                break;
        }
    }
   
    //selectValue
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    [dict setValue:FROM_IOS forKey:@"from"];
    [dict setValue:[XGMArchiverTools cacheForKey:BUSIORGID] forKey:@"busiOrgId"];
    [dict setValue:[XGMArchiverTools cacheForKey:USER_identifierNumber] forKey:@"loginFinger"];
    [dict setValue:[XGMArchiverTools cacheForKey:USER_UserId] forKey:@"userId"];
    
    [dict setValue:self.model.MsgBody.Id forKey:@"msgId"];
    [dict setValue:self.model.Action.Code forKey:@"actionCode"];
    [dict setValue:self.textView.textView.text?self.textView.textView.text:@"" forKey:@"content"];
    //此参数仅限于actionCode=6的时候
    if ([self.model.Action.Code isEqualToString:@"6"]) {
        [dict setValue:self.model.Action.GroupInfo.Option forKey:@"option"];
    }
    //selectValue 当为7或者8的时候就是同意跟不同意 审核 审批
    NSInteger code = [self.model.Action.Code integerValue];
    if (code == 7 || code == 8) {
       [dict setValue:self.code forKey:@"selectValue"];
    }
    
    //点评
    if (code == 6) {
        //GroupInfo.Option=1：隐藏“请选择点评评级“选择项，调用接口时selectValue=0；
        if ([self.model.Action.GroupInfo.Option isEqualToString:@"1"]) {
            [dict setValue:@"1" forKey:@"selectValue"];
        }else{
            if ([self.model.Action.GroupInfo.CheckType isEqualToString:@"1"])
            {
                //等级
                [dict setValue:self.remarkCode forKey:@"selectValue"];
            }else{//评分
                [dict setValue:self.gradeCode forKey:@"selectValue"];
            }
        }
    }

    //图片
    [dict setValue:imgFile1Id forKey:@"imgFile1Id"];
    [dict setValue:imgFile2Id forKey:@"imgFile2Id"];
    [dict setValue:imgFile3Id forKey:@"imgFile3Id"];
    [dict setValue:imgFile4Id forKey:@"imgFile4Id"];
    [dict setValue:imgFile5Id forKey:@"imgFile5Id"];
    //语音
    [dict setValue:voice1Id forKey:@"voice1Id"];
    [dict setValue:voice2Id forKey:@"voice2Id"];
    [dict setValue:voice3Id forKey:@"voice3Id"];

    kWeakObject(self)
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HJNetwork HTTPWithMethod:HJRequestMethodPOST url:[NSString stringWithFormat:@"ajax-api.ashx?$c=TeeyunApp&$m=PostMsgReply&$v=%@",VERSION] parameters:dict cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, NSError *error) {
        [MBProgressHUD hideHUDForView:weakself.view animated:YES];
        if (!error) {
            if ([[responseObject objectForKey:RESULT_NAME_Success] boolValue]) {
                NSString *msg = [responseObject objectForKey:RESULT_NAME_Message];
                if (!msg) {
                    [MBProgressHUD showErrorOrSuc:@"提交成功" toView:weakself.view];
                }else{
                    [MBProgressHUD showErrorOrSuc:msg toView:weakself.view];
                }
                
                /*延迟执行时间2秒*/
                dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC));
                dispatch_after(delayTime, dispatch_get_main_queue(), ^{
                    /**发送通知刷新评论页面*/
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"updataMessage" object:nil];
                    UIViewController * parent = [weakself.view containingViewController];
                    if ([parent respondsToSelector:@selector(dismissSemiModalView)]) {
                        [parent dismissSemiModalView];
                    }
                });
            }else{
                [MBProgressHUD showErrorOrSuc:[responseObject objectForKey:RESULT_NAME_Message] toView:weakself.view];
            }
        }else{
            [MBProgressHUD showErrorOrSuc:@"网络出错" toView:weakself.view];
        }
    }];
}

@end
